import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useMusicPlayListStore = defineStore(
  'music-play-list',
  () => {
    // 音乐播放列表
    const musicPlayList = ref([])
    const setMusicPlayList = (arr) => {
      musicPlayList.value = [...arr]
    }
    const getMusicPlayList = () => {
      return musicPlayList.value.length > 0 ? musicPlayList.value : []
    }

    // 音乐播放索引
    const musicPlayIndex = ref(0)
    const setMusicPlayIndex = (index) => {
      musicPlayIndex.value = index
    }
    const getMusicPlayIndex = () => {
      return musicPlayIndex.value > 0 ? musicPlayIndex.value : 0
    }

    // 音乐播放模式
    const musicPlayMode = ref(0)
    const setMusicPlayMode = (mode) => {
      musicPlayMode.value = mode
    }
    const getMusicPlayMode = () => {
      return musicPlayMode.value > 0 ? musicPlayMode.value : 0
    }
    return {
      // 音乐播放列表
      musicPlayList,
      setMusicPlayList,
      getMusicPlayList,
      // 音乐播放索引
      musicPlayIndex,
      setMusicPlayIndex,
      getMusicPlayIndex,
      // 音乐播放模式
      musicPlayMode,
      setMusicPlayMode,
      getMusicPlayMode
    }
  },
  {
    persist: true // 持久化
  }
)
